package org.boulderfoodrescue.webapp.client.options;

import org.boulderfoodrescue.webapp.client.options.manageusers.ManageUsersPanel;
import org.boulderfoodrescue.webapp.client.options.myinfo.MyInfoPanel;
import org.boulderfoodrescue.webapp.client.options.volunteerinfo.VolunteerInfoPanel;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

public class OptionsPanel extends Composite {

  private static ProfilePanelUiBinder uiBinder = GWT
      .create(ProfilePanelUiBinder.class);

  interface ProfilePanelUiBinder extends UiBinder<Widget, OptionsPanel> {
  }

  public OptionsPanel(MyInfoPanel myInfoPanel, VolunteerInfoPanel volunteerInfoPanel, 
  		ManageUsersPanel manageUsersPanel) {
  	
  	this.myInfoPanel = myInfoPanel;
  	this.volunteerInfoPanel = volunteerInfoPanel;
  	this.manageUsersPanel = manageUsersPanel;
  	
    initWidget(uiBinder.createAndBindUi(this));
    
    History.addValueChangeHandler(new ValueChangeHandler<String>(){
      @Override
      public void onValueChange(ValueChangeEvent<String> event) {
        switchPanel(event.getValue());
      }

    });
    
    switchPanel(History.getToken());
  }
  

  @UiField
  FlowPanel operation_flowPanel;
  
  private MyInfoPanel myInfoPanel;
  private VolunteerInfoPanel volunteerInfoPanel;
	private ManageUsersPanel manageUsersPanel;
  
  public void switchPanel(String panel)
  {
  	if(!panel.contains("options"));
  	else if(panel.contains("volunteerinfo"))
    {
      operation_flowPanel.clear();
      operation_flowPanel.add(volunteerInfoPanel);
    }
    else if(panel.contains("manageUsers"))
    {
      operation_flowPanel.clear();
      operation_flowPanel.add(manageUsersPanel);
    }
    else{
    	operation_flowPanel.clear();
      operation_flowPanel.add(myInfoPanel);
    }
  }


}
